package com.hfh.jdbc;

import java.io.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author hfh
 * @Date 2022 09 20 10 43
 **/
public class JDBCTest4 {
    public static void main(String[] args) throws IOException {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        InputStream is = null;
        try {
            con = DBUtils.getConnection();
            String sql = "select photo from beauty where id = 1 ";
            ps = con.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()){
                is = rs.getBinaryStream("photo");
                IOUtils.transfer(is,"day27/src/copy.png");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            DBUtils.close(con,ps,rs);
            if (is!=null){
                is.close();
            }
        }
    }
}
